package com.yqzl.controller;

import com.yqzl.util.Result;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;

@RestController
public class UserController {

  HashMap<String, String> userMap = new HashMap<String, String>();

  // 模拟已经注册的用户
  {
    userMap.put("wyh", "123");
    userMap.put("admin", "123");
    userMap.put("路飞", "123");
    userMap.put("罗文", "123");
  }

  @RequestMapping("/login")
  //   模拟数据用户登录
  public Result login(@RequestParam("user") String user, @RequestParam("pwd") String pwd) {
    System.out.println("当前要登录的用户====>" + user + "==" + pwd);
//    如果用户没有注册
    if (!userMap.containsKey(user)) {
      return Result.success().setMsg("用户名不存在");
    }

    if (!userMap.get(user).equals(pwd)) {
      return Result.fail().setMsg("密码错误");
    }


    HashMap<Object, Object> map = new HashMap<>();
    map.put("username", user);
    map.put("pwd", userMap.get(user));
    return Result.success().setMsg("登录成功！").setData(map);

  }
}
